#ifndef INITMEASUREMENT_H
#define INITMEASUREMENT_H

#include <QThread>
#include <QString>
#include <QVector>
#include <iostream>
#include <fstream>
#include "imageloader.h"

using namespace cv;

class InitMeasurement : public QThread
{
public:
    InitMeasurement(QObject *parent = 0);
    ~InitMeasurement();
    void addInfo(ImageLoader *loader, int s, int r, int m);
    Mat getResultImg(){ return resultImg;}
    Mat getSkeImg() {return skeImg;}
    Mat getContourImg(){ return contourImg;}
    Mat getBinImg() {return binImg;}
    Mat getGrayImg() {return grayImg;}
    int getNumGerm(){return numGerm;}

protected:
    void run();

private:
    void process(ofstream &out);
    void count();
    void getInitLength(const Mat& img, int rep, Rect &roi);
    void getCurrLength(const Mat& img, Rect &roi);
    int getDiff(double value, Rect &box);
    void toCanny(const Mat& src, Mat& dst);
    void findROI(Mat &src, Rect &roi, int replicate, int seed);
    void toBin(const Mat& src, Mat& dst, int type);
    void toSkeleton(const Mat& src, Mat& dst);
    void getStat(Mat &src, ofstream &out, int row);
    void addToMat(const Mat& info, int row, double value, Rect &box);
    QString getOutFile();

    QPointer<ImageLoader> imgL;
    Mat resultImg, skeImg, contourImg, binImg, grayImg;
    QString initfile, currfile;					// Initial file and curr file
    int seed, replicate, method, numGerm;		// Parameters: type of seed, replicate index, 
    int caT1, caT2;								// Threshold value for canny operation
    int inter[6];								// Replicate index
    Rect roi;									// Global variable for image roi
    Mat info, initial;							// Matrix that store length and area 
};

#endif // INITMEASUREMENT_H
